package com.kushe.site.controller;

import com.kushe.dao.CommentDao;
import com.kushe.dao.TopicsDao;
import com.kushe.entity.Comment;
import com.kushe.entity.Topics;
import com.kushe.entity.User;
import com.kushe.util.KSController;
import com.kushe.util.SessionEnv;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * Created by WSDevotion on 2015/5/29.
 */
@Controller
@RequestMapping("/repeat")
public class RepeatController extends KSController {

    //进入评论页面
    @RequestMapping("addrepeat")
    public Object toRepeatindex(int id, Comment comment, HttpServletRequest request) {
        //通过id查询话题
        Topics topic = TopicsDao.get(id);
        if (topic == null) {
            return "error";
        }
        //从session中得到user
        User user = ((SessionEnv) request.getSession().getAttribute("user")).getUser();
        comment.setComment_time(new Date());
        comment.setTopic_id(id);
        comment.setUser_id(user.getId());
        CommentDao.addComment(comment);
        return this.render("redirect:/topic/goTopic?id=" + id);
    }
}
